package com.ms.p2p.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.ms.p2p.controller.BaseController;
import com.ms.p2p.entity.loan.Loan;
import com.ms.p2p.entity.loan.LoanStay;
import com.ms.p2p.entity.loan.LoanTenderRecord;
import com.ms.p2p.entity.member.Auth;
import com.ms.p2p.entity.member.Member;
import com.ms.p2p.provider.*;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping({ "/agreement" })
public class AgreementController extends BaseController{

    @Reference
    LoanProvider loanProvider;

    @Reference
    LoanTenderRecordProvider loanTenderRecordProvider;
    @Reference
    CertiFiCationProvider certiFiCationProvider;

    @Reference
    MemberProvider memberProvider;
    @Reference
    LoanStayProvider loanStayProvider;
    @RequestMapping("/bid/{bid}")
    public String error(@PathVariable String bid, HttpServletRequest request,HttpServletResponse response, HttpSession session) {
        String agreementId = "Loan_Agreement_"+bid;
        Loan loan = loanProvider.findById(bid);
        List<LoanTenderRecord> recordList = loanTenderRecordProvider.getList(loan.getId());
        List<LoanStay> staylist = loanStayProvider.findList(loan.getId());
        Member member = memberProvider.findById(loan.getUser_id());
        Auth auth = certiFiCationProvider.findByUserId(member.getId());
        request.setAttribute("member",member);
        request.setAttribute("auth",auth);
        request.setAttribute("agreementId",agreementId);
        request.setAttribute("loan",loan);
        request.setAttribute("stayList",staylist);
        request.setAttribute("recordList",recordList);
        return "customer/agreement";


    }


}
